package com.qiulingcloud.order.controller;


import com.qiulingcloud.commonsserver.entity.TestOrder;
import com.qiulingcloud.commonsserver.entity.vo.DataResult;
import com.qiulingcloud.commonsserver.entity.vo.PageReqVO;
import com.qiulingcloud.commonsserver.entity.vo.PageVO;
import com.qiulingcloud.order.service.TestOrderService;
import com.qiulingcloud.order.vo.req.TestOrderAddReqVO;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangqiang
 * @since 2020-04-27
 */
@RestController
@RequestMapping("testOrder")
public class TestOrderController {

    @Autowired
    private TestOrderService testOrderService;
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @PostMapping("orders")
    @ApiOperation(value = "分页+条件查询订单列表")
    public DataResult<PageVO<TestOrder>> orderInfo(@RequestBody PageReqVO vo) {
        DataResult result = DataResult.success();
        result.setData(testOrderService.pageInfo(vo));
        return result;
    }

    @PostMapping("order")
    @ApiOperation(value = "新增订单")
    public DataResult<PageVO<TestOrder>> createOrder(@RequestBody TestOrderAddReqVO vo) {
        //TODO 这里userId先写死
        String userId = "fcf34b56-a7a2-4719-9236-867495e74c31";
        DataResult result = DataResult.success();
        testOrderService.createOrder(vo, userId);
        return result;
    }

    @GetMapping("getString")
    @ApiOperation(value = "测试限流")
    public String getString() {
        return "测试限流";
    }

    @GetMapping("sendMessage")
    @ApiOperation(value = "测试rocketmq发送信息")
    public String sendMessage() {
        rocketMQTemplate.convertAndSend("order-topic", "测试订单发送消息");
        return "订单服务发送消息成功";
    }
}

